﻿using System;
using PasswordControl.Core.Data;

namespace PasswordControl.UI.WPF.ViewModel.PasswordItem
{
    class PasswordItemViewModel : ViewModelBase
    {
        private IPasswordItem m_item;
        private bool m_showPassword = false;

        public string ItemName
        {
            get { return m_item.ItemName; }
            set { m_item.ItemName = value; }
        }

        public string Username
        {
            get { return m_item.Username; }
            set { m_item.Username = value; }
        }

        public string Password
        {
            get { return (m_showPassword) ? m_item.Password : string.Empty; }
            set { if (m_showPassword) m_item.Password = value; }
        }

        public string Group
        {
            get { return m_item.Group; }
            set { m_item.Group = value; }
        }

        public bool ShowPassword
        {
            get { return m_showPassword; }
            set 
            { 
                m_showPassword = value; 
                OnPropertyChanged(o => (o as PasswordItemViewModel).Password);
                OnPropertyChanged(o => (o as PasswordItemViewModel).ShowPassword);
            }
        }

        public PasswordItemViewModel(IPasswordItem item)
        {
            m_item = item;
            if (string.IsNullOrEmpty(item.Password)) ShowPassword = true;
        }
    }
}
